using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace MacViet.DataBaseAPI
{
    /// <summary>
    /// Description: Concrete DataProvider for table Services. Provides atomic API functions.
    /// Author:  phong.huynh
    /// Created: 13/08/2010 10:10:40 SA
    /// </summary>
    public class SERVICESDataAPI
    {
        private SQLHelper _dbTool = new SQLHelper();


        // ************************************
        // Implements function getByColumnName
        // ************************************

        public DataTable getBySER_ID(System.Int32 SERCAT_ID,System.Int32 ACC_ID)
        {
            SqlParameter[] parm = { new SqlParameter(ACCOUNTSDTO._ACC_ID,ACC_ID),
                                      new SqlParameter(SERVICESDTO._SERCAT_ID, SERCAT_ID) };
            return _dbTool.executeReader("SP_SEL_SERVICES_getBySER_ID", parm);
        }




        public DataTable getBySERCAT_ID(System.Int32 SERCAT_ID, System.Int32 ACC_ID)
        {
            SqlParameter[] parm = {new SqlParameter(ACCOUNTSDTO._ACC_ID,ACC_ID),
                                      new SqlParameter(SERVICESDTO._SERCAT_ID, SERCAT_ID) };
            return _dbTool.executeReader("SP_SEL_SERVICES_getBySERCAT_ID", parm);
        }
        
        // *************************************************
        // Implement function getAll/getByDynamicCondition
        // *************************************************

        public DataTable getAll()
        {
            return _dbTool.executeReader("SP_SEL_SERVICES_getAll");
        }

        public DataTable getServices_Edit(System.Int32 ACC_ID)
        {
            SqlParameter[] parm = { new SqlParameter(SERVICESDTO._ACC_ID, ACC_ID) };
            return _dbTool.executeReader("SP_SET_SERVICES_GetEditServices",parm);
        }


        public DataTable getServices_Price(System.Int32 SER_ID,System.Int32 ACC_ID)
        {
            SqlParameter[] parm = {  new SqlParameter(SERVICESDTO._SER_ID, SER_ID) ,
                                      new SqlParameter(SERVICESDTO._ACC_ID, ACC_ID) };
            return _dbTool.executeReader("GET_SERVICE_PRICE", parm);
        }



        public DataTable getServicesPriceList()
        {
            return _dbTool.executeReader("SQL_SET_SERVICES_GetSER_PRICELIST");
        }
        // ********************************************************
        // Implement function getByPrimaryKeys / getByForeignKeys
        // In case table have composite primary/foreign keys
        // ********************************************************

        public DataTable getByPrimaryKeys(System.Int32 SER_ID)
        {
            SqlParameter[] parm = { new SqlParameter(SERVICESDTO._SER_ID, SER_ID) };
            return _dbTool.executeReader("SP_SEL_SERVICES_getByPrimaryKeys", parm);
        }


        public void insertSERVICES(System.Int32 SERCAT_ID, System.String SER_NAME, System.String SER_DESCRIPTION, System.Decimal SER_PRICE, System.Int32 ACC_ID)
        {
            SqlParameter[] parm = { new SqlParameter(SERVICESDTO._SERCAT_ID,SERCAT_ID),
                                    new SqlParameter(SERVICESDTO._SER_NAME,SER_NAME),
                                    new SqlParameter(SERVICESDTO._SER_DESCRIPTION,SER_DESCRIPTION),
                                    new SqlParameter(SERVICESDTO._SER_PRICE,SER_PRICE),
                                    new SqlParameter(SERVICESDTO._ACC_ID,ACC_ID)};
            int effectedRows = _dbTool.ExecuteNoneQuery("SP_INS_SERVICES_values", parm);
        }
        //
        public void updateSERVICES(System.Int32 SER_ID, System.Int32 SERCAT_ID, System.String SER_NAME, System.String SER_DESCRIPTION, System.Decimal SER_PRICE)
        {
            SqlParameter[] parm = {new SqlParameter(SERVICESDTO._SER_ID,SER_ID),
                                    new SqlParameter(SERVICESDTO._SERCAT_ID,SERCAT_ID),
                                    new SqlParameter(SERVICESDTO._SER_NAME,SER_NAME),
                                    new SqlParameter(SERVICESDTO._SER_DESCRIPTION,SER_DESCRIPTION),
                                    new SqlParameter(SERVICESDTO._SER_PRICE,SER_PRICE)};
            int affectRows = _dbTool.ExecuteNoneQuery("SP_UDP_SERVICES_update", parm);
        }

        ///<summary>		
        /// Thu+.c hie^.n ca^u le^.nh update du+.a tre^n kho'a chi'nh
        ///</summary>

        //public bool updateSERVICES(System.Int32 SER_ID, System.Int32 SERCAT_ID, System.String SER_NAME, System.String SER_DESCRIPTION, System.Decimal SER_PRICE)
        //{
        //    SqlParameter[] parm = { new SqlParameter(SERVICESDTO._SER_ID,SER_ID),
        //                            new SqlParameter(SERVICESDTO._SERCAT_ID,SERCAT_ID),
        //                            new SqlParameter(SERVICESDTO._SER_NAME,SER_NAME),
        //                            new SqlParameter(SERVICESDTO._SER_DESCRIPTION,SER_DESCRIPTION),
        //                            new SqlParameter(SERVICESDTO._SER_PRICE,SER_PRICE)};
        //    int affectRows = _dbTool.ExecuteNoneQuery("SP_UDP_SERVICES_update", parm);

        //    return affectRows == 1;
        //}


        // ********************************************************************************
        // Implementation of deleteAll/deteleByForeignKeys/deleteByPrimaryKeys function		
        // ********************************************************************************

        // return number of deleted rows		
        public int deleteAll()
        {
            return _dbTool.ExecuteNoneQuery("SP_DEL_SERVICES_deleteAll");
        }

        // return number of deleted rows
        public int deleteByPrimaryKeys(System.Int32 SER_ID)
        {
            SqlParameter[] parm = { new SqlParameter(SERVICESDTO._SER_ID, SER_ID) };
            return _dbTool.ExecuteNoneQuery("SP_DEL_SERVICES_deleteByPrimaryKeys", parm);
        }

    }
}